package com.example.property.adapter

import android.graphics.Color
import android.provider.ContactsContract.Data
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.property.databinding.ItemApplyBinding
import com.example.property.entity.ParkApplyValues
import java.text.SimpleDateFormat
import java.util.Date

class ParkApplyAdapter constructor(private val list :MutableList<ParkApplyValues>):RecyclerView.Adapter<ParkApplyAdapter.ItemViewHolder>() {

    inner class ItemViewHolder(val dataBinding: ItemApplyBinding):RecyclerView.ViewHolder(dataBinding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
      var dataBinding=ItemApplyBinding.inflate(LayoutInflater.from(parent.context),parent,false)
        return ItemViewHolder(dataBinding)
    }

    override fun getItemCount(): Int =list.size

    override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
       var entity =list[position]
        when(entity.type){
            0 -> entity.color = Color.parseColor("#1E90FF")
            1 -> entity.color = Color.parseColor("#008000")
            2 -> entity.color = Color.parseColor("#008000")
        }
        //转换时间
//        if (!isValidDate(entity.applyTime)){
//            if (entity.applyTime.length>10){
//                entity.applyTime= SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date(entity.applyTime.toLong() / 1000L)).toString()
//            }else{
//                entity.applyTime= SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date(entity.applyTime.toLong() * 1000L)).toString()
//            }
//        }
        if (entity.applyTime == "string"){
            entity.applyTime = "yyyy-MM-dd".format(System.currentTimeMillis())
        }
        holder.dataBinding.entity=entity
    }
    /**
     * 时间格式判断
     * */

    fun isValidDate(dateStr: String): Boolean {
        val regex ="^(\\d{5})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})$"
        return dateStr.matches(regex.toRegex())
    }


}